package com.xbongbong.parent.interfaces;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataUpdateDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.pojo.UpdateValidateReturnPojo;
import com.xbongbong.pro.formdata.pojo.SaasNeedRedundantAttrPojo;
import com.xbongbong.pro.formdata.pojo.vo.BeforeUpdateVO;

import java.util.List;
import java.util.Map;

/**
 * @author 吴峰
 * @date 2021/12/28 16:11
 */
public interface BusinessUpdateBeforeService<F, D> {


    /**
     * 更新权限的校验
     * com.xbongbong.paas.help.ProPermissionHelp#verifyEditPermission(com.xbongbong.pro.permission.pojo.dto.VerifyUpdatePermissionDTO)
     * @param formDataUpdateDTO
     * @throws XbbException
     */
    void validatePermission(FormDataUpdateDTO formDataUpdateDTO) throws XbbException;
    /**
     * 获取表单
     * @param formDataUpdateDTO
     * @return
     * @throws XbbException
     */
    F getForm(FormDataUpdateDTO formDataUpdateDTO) throws XbbException;

    /**
     * 获取数据实体
     * @param formDataUpdateDTO
     * @param explainMap
     * @return
     * @throws XbbException
     */
    D getFormData(FormDataUpdateDTO formDataUpdateDTO, Map<String, FieldAttrEntity> explainMap) throws XbbException;
    /**
     * 获取字段解释
     * @param corpid
     * @param formId
     * @param saasMark
     * @param businessType
     * @return
     * @throws XbbException
     */
    List<FieldAttrEntity> getExplainList(FormDataUpdateDTO formDataUpdateDTO, String corpid, Long formId, Integer saasMark, Integer businessType) throws XbbException;

    /**
     * 设置导入不能修改的数据
     * @param fieldAttrEntity
     * @param oldData
     * @param newData
     * @throws XbbException
     */
    void businessImportSetData(FieldAttrEntity fieldAttrEntity, JSONObject oldData, JSONObject newData);

    /**
     * 各个业务层的解析数据，目前都封装在接口SaasValidateAnalyticalService
     * @param validateDataDTO
     * @param oldPaasFormDataEntity
     * @param explainMap
     * @throws XbbException
     * @return
     */
    UpdateValidateReturnPojo analyticalData(FormDataUpdateDTO formDataUpdateDTO, ValidateDataDTO validateDataDTO, D oldPaasFormDataEntity, Map<String, FieldAttrEntity> explainMap) throws XbbException;

    /**
     * 各个业务层的解析数据，目前都封装在接口SaasValidateAnalyticalService
     * @param validateDataDTO
     * @param oldPaasFormDataEntity
     * @param explainMap
     * @param formDataUpdateDTO
     * @throws XbbException
     */
    void importAnalyticalData(ValidateDataDTO validateDataDTO, D oldPaasFormDataEntity, Map<String, FieldAttrEntity> explainMap, FormDataUpdateDTO formDataUpdateDTO) throws XbbException;

    /**
     * 拼装更新的实体
     * @param formDataUpdateDTO
     * @param oldPaasFormDataEntity 数据库中的数据
     * @param data
     * @param departmentId
     * @return
     * @throws XbbException
     */
    D getData(FormDataUpdateDTO formDataUpdateDTO,  D oldPaasFormDataEntity, JSONObject data, Long departmentId) throws XbbException;


    /**
     * 导入拼装更新的实体
     * @param formDataUpdateDTO
     * @param explainMap
     * @param oldPaasFormDataEntity 数据库中的数据
     * @param data
     * @param departmentId
     * @return
     * @throws XbbException
     */
    D getImportData(FormDataUpdateDTO formDataUpdateDTO, Map<String, FieldAttrEntity> explainMap, D oldPaasFormDataEntity, JSONObject data, Long departmentId) throws XbbException;

    /**
     * 开始审批流，导入调用
     * @param paasFormDataEntity
     * @param oldFormData
     * @param paasFormEntityExt
     * @param saasNeedRedundantAttrPojo
     * @param formDataAddDTO
     * @param explainMap
     * @param explainList
     * @return com.xbongbong.pro.formdata.pojo.vo.BeforeSaveVO
     * @author 吴峰
     * @date 2022/1/10 15:35
     * @throws XbbException
     */
    BeforeUpdateVO startWorkFlowOrProcess(D paasFormDataEntity, D oldFormData, F paasFormEntityExt, SaasNeedRedundantAttrPojo saasNeedRedundantAttrPojo, FormDataUpdateDTO formDataAddDTO, Map<String, FieldAttrEntity> explainMap, List<FieldAttrEntity> explainList) throws XbbException;
    /**
     * 开始审批流，导入调用
     * @param paasFormDataEntity
     * @param oldFormData
     * @param paasFormEntityExt
     * @param saasNeedRedundantAttrPojo
     * @param formDataAddDTO
     * @param explainMap
     * @param explainList
     * @return com.xbongbong.pro.formdata.pojo.vo.BeforeSaveVO
     * @author 吴峰
     * @date 2022/1/10 15:35
     * @throws XbbException
     */
    BeforeUpdateVO startWorkFlow(D paasFormDataEntity, D oldFormData, F paasFormEntityExt, SaasNeedRedundantAttrPojo saasNeedRedundantAttrPojo, FormDataUpdateDTO formDataAddDTO, Map<String, FieldAttrEntity> explainMap, List<FieldAttrEntity> explainList) throws XbbException;
    /**
     * 开始审批流
     * @param paasFormEntityExt
     * @param formDataUpdateDTO
     * @param oldPaasFormDataEntity
     * @param paasFormDataEntity
     * @return
     * @throws XbbException
     */
    Integer startProcess(FormDataUpdateDTO formDataUpdateDTO, D paasFormDataEntity, D oldPaasFormDataEntity, F paasFormEntityExt, SaasNeedRedundantAttrPojo saasNeedRedundantAttrPojo) throws XbbException;

    /**
     * 判断是否触发工作流
     * @param formDataUpdateDTO
     * @param explainMap
     * @param paasFormDataEntity
     * @param oldPaasFormData
     * @return
     * @throws XbbException
     */
    boolean isEnableNewWorkflow(FormDataUpdateDTO formDataUpdateDTO, Map<String, FieldAttrEntity> explainMap, D paasFormDataEntity, D oldPaasFormData) throws XbbException;


    /**
     * 单条编辑触发工作流
     * @param formDataUpdateDTO
     * @param beforeSaveVO
     * @param formDataSaveVO
     * @throws XbbException
     */
    void workflowUpdateTrigger(FormDataUpdateDTO formDataUpdateDTO, BeforeUpdateVO beforeSaveVO, FormDataUpdateVO formDataSaveVO, D paasFormDataEntity, D oldPaasFormData) throws XbbException;
}
